/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.feedback.manage.controller;


import info.peigen.hotpot.common.core.result.manage.WebResult;
import info.peigen.hotpot.component.data.repository.beetlsql.filter.ManageDataAspect;
import info.peigen.hotpot.component.feedback.form.FeedbackManageDeleteForm;
import info.peigen.hotpot.component.feedback.form.FeedbackManageEditForm;
import info.peigen.hotpot.component.feedback.form.FeedbackManageSearchForm;
import info.peigen.hotpot.component.feedback.manage.service.FeedbackManageService;
import info.peigen.hotpot.component.feedback.result.FeedbackDeleteResult;
import info.peigen.hotpot.component.feedback.result.FeedbackEditResult;
import jakarta.validation.Valid;
import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;

/**
 * <b>(FeedbackManageController)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/6
 */
@Controller
@Mapping("feedback")
public class FeedbackManageController {
    @Inject
    private FeedbackManageService feedbackManageService;

    @Mapping
    @ManageDataAspect
    WebResult page(@Body FeedbackManageSearchForm form) {
        return WebResult.setSuccessResult().setInfo(feedbackManageService.page(form));
    }

    @Mapping("edit")
    @ManageDataAspect
    WebResult edit(@Valid @Body FeedbackManageEditForm form) {
        FeedbackEditResult result = feedbackManageService.edit(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

    @Mapping("delete")
    @ManageDataAspect
    WebResult delete(@Valid @Body FeedbackManageDeleteForm form) {
        FeedbackDeleteResult result = feedbackManageService.delete(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

}